#include <stdio.h>
#include <string.h>

char ss[100];
int tu[10][10];
int ans;
int win;

bool in()
{
    scanf("%s", ss);
    if (ss[0] == 'e') return false;
    return true;
}   
inline int getval(char ch)
{
    if (ch=='X') return 1;
    else if (ch=='O') return 2;
    return 0;
}   
void checkover()
{
    int x, y, a, b, i, j;
    int cnt[5];
    ans = 0;
    for (i=1; i<=3; ++i)
    {
        cnt[1] = cnt[2] = 0;
        for (j=1; j<=3; ++j)
            cnt[tu[i][j]]++;    
        if (cnt[1]==3 || cnt[2]==3) ans++;
    }    
    for (i=1; i<=3; ++i)
    {
        cnt[1] = cnt[2] = 0;
        for (j=1; j<=3; ++j)
            cnt[tu[j][i]]++;    
        if (cnt[1]==3 || cnt[2]==3) ans++;
    }   
    
    cnt[1]=cnt[2]=0; 
    for (i=1; i<=3; ++i)
    {
        cnt[tu[i][i]]++;
    }        
    if (cnt[1]==3 || cnt[2]==3) ans++;
    
    cnt[1]=cnt[2]=0; 
    for (i=1; i<=3; ++i)
    {
        cnt[tu[i][4-i]]++;
    }        
    if (cnt[1]==3 || cnt[2]==3) ans++;
}     

void check()
{
    int x, y, a, b, i, j;
    int cnt[5];
    ans = 0;
    for (i=1; i<=3; ++i)
    {
        cnt[1] = cnt[2] = 0;
        for (j=1; j<=3; ++j)
            cnt[tu[i][j]]++;    
        if (cnt[1]==3 || cnt[2]==3) ans++;
    }    
    for (i=1; i<=3; ++i)
    {
        cnt[1] = cnt[2] = 0;
        for (j=1; j<=3; ++j)
            cnt[tu[j][i]]++;    
        if (cnt[1]==3 || cnt[2]==3) ans++;
    }   
    
    cnt[1]=cnt[2]=0; 
    for (i=1; i<=3; ++i)
    {
        cnt[tu[i][i]]++;
    }        
    if (cnt[1]==3 || cnt[2]==3) ans++;
    
    cnt[1]=cnt[2]=0; 
    for (i=1; i<=3; ++i)
    {
        cnt[tu[i][4-i]]++;
    }        
    if (cnt[1]==3 || cnt[2]==3) ans++;
}     
 
bool precheck()
{
    int i, j;
    int cnt[4];
    cnt[1] = cnt[2] = 0;
    for (i=1; i<=3; ++i)
        for (j=1; j<=3; ++j)
            cnt[ tu[i][j] ] ++;
    if (cnt[1] == cnt[2])
    {
         win = 2;
         return true;
    }    
    if (cnt[1] == cnt[2]+1)
    {
        win = 1;
        return true;
    }    
    return false;
}     
 
bool deal()
{
    int i, j, x, y, len;
    x = 1; y = 1;
    len = strlen(ss);
    for (i=0; i<len; ++i)
    {
        tu[x][y] = getval(ss[i]);
        y++;
        if (y==4) x++, y=1;
    }
    
    if (precheck()==false) return false;
    
    check();
    if (ans==0)
    {
        for(i=1; i<=3; ++i)
           for (j=1; j<=3; ++j)
              if (tu[i][j]==0)
                   return false;
    }    
    
    int tmp;
    for (i=1; i<=3; ++i)
        for (j=1; j<=3; ++j)
            if ((tmp=tu[i][j])==win)
            {
                tu[i][j] = 0;
                check();
                if (ans==0) return true;
                tu[i][j] = tmp;
            }    
    return false;
}    

int main()
{
    while (in())
    {
        if (deal()) printf("valid\n");
        else printf("invalid\n");
    }        
    
    return 0;
}    
